package top.jacktgq.itheima.bio;

import java.net.InetAddress;
import java.net.UnknownHostException;

/*
 * 表示是互联网中的IP地址
 *    java.net.InetAddress
 * 静态方法
 *    static InetAddress getLocalHost()
 *    LocalHost 本地主机
 *    返回本地主机，返回值是InetAddress对象
 * 
 *    
 */
public class InetAddressDemo {
	
	public static void main(String[] args) {
		//function_1();
		function_2();
	}
	
	/*
	 * static InetAddress getLocalHost()
	 */
	public static void function_1(){
		try {
			InetAddress inet = InetAddress.getLocalHost();
			System.out.println(inet);
			/*String host = inet.toString();
			String[] str = host.split("/");
			System.out.println("主机名是："+str[0]+"，IP地址名是："+str[1]);*/
			String ip = inet.getHostAddress();
			String hostname = inet.getHostName();
			System.out.println(ip+hostname);
			System.out.println();
 		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
	}
	
	/*
	 * static InetAddress getByName(String hostName)传递主机名，获取IP地址对象
	 */
	public static void function_2(){
		try {
			InetAddress inet = InetAddress.getByName("www.JackTGQ.top");
			System.out.println(inet);
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
	}
}
